<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('收款记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
         <div class="row">
             <div class="col-sm-12 search-collapse">
                 <p class="select-title"><b>[[${title}]]</b> 收款记录</p>
                 <form id="formId">
                     <div class="select-list">
                         <ul>
                             <li>
                                 <label>删除状态：</label>
                                 <select name="deleteFlag" class="form-control" th:with="type=${@dict.getType('sys_normal_disable')}">
                                     <option value="">全部</option>
                                     <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue == 0}"></option>
                                 </select>
                                 <input type="hidden" name="planId" th:value="${plan.id}" />
                             </li>
                             <li>
                                 <label>审批状态：</label>
                                 <select name="status" class="form-control" th:with="type=${@dict.getType('approve_status')}">
                                     <option value="">全部</option>
                                     <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                 </select>
                             </li>
                             <li>
                                 <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                 <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                             </li>
                         </ul>

                     </div>
                 </form>
             </div>
        <div class="row">
            <div class="btn-group-sm" id="toolbar" role="group">

                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:detail:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-success" onclick="enableAll()" shiro:hasPermission="erp:receivable:approve">
                    <i class="fa fa-check"></i> 批量通过
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:detail:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:detail:remove')}]];
        var statusDatas = [[${@dict.getType('approve_status')}]];
        var deleteFlagDatas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "erp/receivable/detail";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/other/" + [[${plan.id}]],
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "收款记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'title',
                    title: '项目/结算名称'
                },
                {
                    field: 'receiveAmount',
                    title: '收款金额',
                },
                {
                    field: 'bankName',
                    title: '收款账户'
                },
                {
                    field: 'receiveTime',
                    title: '收款时间'
                },
                {
                    field: 'receiverName',
                    title: '收款人'
                },
                {
                    field: 'status',
                    title: '审批状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'description',
                    title: '备注'
                },
                {
                    field: 'deleteFlag',
                    title: '删除标志',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(deleteFlagDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var editUrl = prefix + "/edit/"+ row.id;
                        if (row.plan.planType == 'staffing'){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.modal.open(\''+ row.title +'\',\'' + editUrl + '\',1120)"><i class="fa fa-edit"></i>编辑</a> ');
                        }else {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.modal.open(\''+ row.title +'\',\'' + editUrl + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }

                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /* 审批状态显示 */
        function statusTools(row) {
            if (row.status == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        /* 审批-停用 */
        function disable(id) {
            $.modal.confirm("确认未通过此收款吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "ids": id, "status": 1 });
            })
        }

        /* 审批启用 */
        function enable(id) {
            $.modal.confirm("确认要通过此收款吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "ids": id, "status": 0 });
            })
        }

        function enableAll()
        {
            let ids = $.table.selectColumns("id");
            if (ids.length <=0){
                $.modal.alertError("至少选择一条记录");
                return;
            }
            enable(ids.toString());
        }
    </script>
</body>
</html>